﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NFit.Core.BaseClasses
{
    /// <summary>
    /// Base class for runnable list that could have an implementation
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="TImpl"></typeparam>
    public abstract class RunnableActiveList<T, TImpl> : RunnableList<T> where T : RunnableElement
    {
        private string _className;

        /// <summary>
        /// The name of the implementation's class
        /// </summary>
        public string ClassName
        {
            get
            {
                if (ClassType != null)
                    return ClassType.Name;

                return _className;
            }
            set
            {
                _className = value;
            }
        }

        /// <summary>
        /// The type of the implementation's class
        /// </summary>
        public Type ClassType { get; set; }

        /// <summary>
        /// The arguments of the fixture, usually the arguments of the implementation's constructor
        /// </summary>
        public FixtureRow Arguments { get; set; }

        /// <summary>
        /// Indicate if the element as an implementation defined
        /// </summary>
        public bool HasClass
        {
            get
            {
                return (!string.IsNullOrEmpty(ClassName)) || (ClassType != null);
            }
        }

        /// <summary>
        /// The element implementation
        /// </summary>
        public TImpl Implementation { get; set; }

        /// <summary>
        /// Get an instance of the fixture's implementation
        /// </summary>
        /// <returns>an instance of the fixture's implementation</returns>
        public TImpl GetImplementation()
        {
            // TODO gérer les arguments et vérifier que le type correspond à TImpl
            return (TImpl)ClassType.Assembly.CreateInstance(ClassType.FullName);
        }
    }
}
